<template>
  <section class="voucher-detail">
    <progress-indicator :status.sync="status" v-if="loaded"/>
    <div class="data-content" v-if="loaded">
      <template v-if="status==0">
      <div v-if="true">
        <el-button size="medium" @click="back">
          返回
        </el-button>
        <el-button type="primary" size="medium" @click="saveBaseInfo">
          确定
        </el-button>
      </div>
      <div class="container">
        <upload-basic-info ref="uploadBaseInfo" :clientInfo="clientInfo" />
      </div>
      </template>
      <template v-if="status==1">
      <div v-if="true">
        <el-button size="medium" @click="back">
          返回
        </el-button>
        <el-button type="primary" size="medium" @click="rollback">
          重新上传
        </el-button>
      </div>
      <div class="container">
      <upload-item-table />
      </div>
      </template>
    </div>
  </section>
</template>


<script>
import progressIndicator from "@/pages/companies/batchAdd/progressIndicator";
import uploadBasicInfo from "@/pages/companies/batchAdd/uploadBasicInfo";
import uploadItemTable from "@/pages/companies/batchAdd/uploadItemTable";
import utiles from '@/components/utiles';

const names = {
  specialVatInvoice: "已认证的增值税专用发票",
  otherDeductItem: "其他抵扣项",
  inTaxOutItem: "进税项转出",
  totalItem: "总计",
};
export default {
  data() {
    return {
      clientInfo: {},
      bName:'',
      status:1,
      imageBase64: "",
      loaded: false,
    };
  },

  components: {
    progressIndicator,
    uploadBasicInfo,
    uploadItemTable
  },

  created() {
    const currentUser = utiles.getCurrentUser();
    const data = localStorage.getItem("valueAddedTaxDetail");
    this.bName = currentUser.bCompanyName;
    if (data) {
      this.clientInfo = JSON.parse(data);
      console.log('clientInfo: ', this.clientInfo);
      this.loadProgress();
    }
  },

  methods: {
    loadProgress() {
      this.$http
        .get("/batchInput/getInputStatus", {
          params: {
            bName:this.bName,
          },
        })
        .then((res) => {
          if (res.code == 0) {
            this.status = res.data.status;
            this.loaded = true;
          }
        });
    },
    back(){
      this.$router.back()
    },
    saveBaseInfo(){
     const baseInfo = this.$refs.uploadBaseInfo.getValue();
    const params = {
                bName: this.bName,
                ...baseInfo
            };

    this.$http.get('/batchInput/saveBaseInfo', {params:params}).then(res => {
                // this.$router.push('/companies');
                this.loadProgress();
            });
    },
    rollback(){
      this.$http.post("/batchInput/rollback", {
        bName: this.bName
      }).then((res) => {
        if (res.code != -1){
          this.$message.success("回退成功");
          location.reload();
        }
      });
    }
  },
};
</script>
<style scoped>
.voucher-detail {
  padding: 0 10px;
}
.header-item {
  font-size: 14px;
  color: #333;
}
.data-content {
  margin-top: 20px;
  padding: 20px 20px 40px;
  background: #fff;
  box-sizing: border-box;
}
.btns-content {
  margin-bottom: 30px;
}
.container{
  display: flex;
  display: -webkit-flex;
  align-items:center;
  justify-content:center;
}
</style>
